package 并发编程;

import java.util.concurrent.TimeUnit;

public class DemoThread extends Thread{

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(new DemoThread());
        t.start();
        TimeUnit.SECONDS.sleep(1);
        t.interrupt();
        Class clazz = DemoThread.class;
    }
//
    @Override
    public void run() {
        while (!Thread.currentThread().isInterrupted()) {
            System.out.println("i am working...");
            try {
                  Thread.sleep(5000);
//                boolean flag = Thread.interrupted();
//                System.out.println("interrupted:" + flag);
//                this.wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
                System.out.println("is interrupted");
                Thread.currentThread().interrupt();
            }
        }
    }
}
